using System;
using NUnit.Framework;
using ValidationFramework;

namespace ExampleLibraryCSharp.ParameterValidationManagerExamples
{
	public class BasicHandleExample
	{
		#region Example
		public class Person
		{
			private static readonly RuntimeMethodHandle checkAgeHandle =
				typeof(Person).GetMethod("CheckAge").MethodHandle;

			public void CheckAge(
				[CompareIntRule(5, CompareOperator.LessThan)] int age)
			{
				ParameterValidationManager.ThrowException(this, checkAgeHandle, age);

				//business code goes here.
			}
		}

		[TestFixture]
		public class ExampleUsage
		{
			[Test]
			[ExpectedException(typeof(ArgumentException))]
			public void RunInvalidData()
			{
				var person = new Person();
				person.CheckAge(7);
			}


			[Test]
			public void RunValidData()
			{
				var person = new Person();
				person.CheckAge(2);
			}
		}
		#endregion
	}
}